package com.hl.ruoyilkshop.controller;

import com.hl.ruoyilkshop.service.ISearchService;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 搜索管理Controller
 * 
 * @author ruoyi
 * @date 2025-01-27
 */
@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private ISearchService searchService;

    /**
     * 搜索商品
     */
    @GetMapping("/goods")
    public AjaxResult searchGoods(
            @RequestParam String keyword,
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize) {
        return searchService.searchGoods(keyword, pageNum, pageSize);
    }

    /**
     * 添加商品到搜索索引
     */
    @PostMapping("/goods/{goodsId}")
    public AjaxResult addGoodsToIndex(@PathVariable Long goodsId) {
        return searchService.addGoodsToIndex(goodsId);
    }

    /**
     * 从搜索索引删除商品
     */
    @DeleteMapping("/goods/{goodsId}")
    public AjaxResult deleteGoodsFromIndex(@PathVariable Long goodsId) {
        return searchService.deleteGoodsFromIndex(goodsId);
    }

    /**
     * 同步所有商品到搜索索引
     */
    @PostMapping("/goods/sync-all")
    public AjaxResult syncAllGoodsToIndex() {
        return searchService.syncAllGoodsToIndex();
    }
} 